/*************************************************************************
> File Name: 02_test.cpp
> Author: hzy
> Created Time: 2023-08-14 17:48:40
> Description:菱形继承
************************************************************************/
#include <iostream>

using namespace std;

// 虚基类
class BigBase
{
public:
    BigBase(int x) { Val = x; }
    void func() { cout << "BigBase::func" << endl; }
    int getVal() { return Val; }

public:
    int Val;
};

class Base1 : virtual public BigBase
{
public:
    Base1() : BigBase(56) // 不调用 BigBase 构造
    {
        cout << "Base1()" << endl;
    }
};

class Base2 : virtual public BigBase
{
public:
    Base2() : BigBase(10) // 不调用 BigBase 构造
    {
        cout << "Base2()" << endl;
    }
};

class Son : public Base1, public Base2
{
public:
    Son() : BigBase(15) // 调用 BigBase 构造
    {
        cout << "Son()" << endl;
    }
    void showVal()
    {
        cout << BigBase::getVal() << endl;
    }
};

int main()
{
    Son son;
    son.func();
    cout << son.Val << endl;
    son.showVal();

    return 0;
}